package com.roncoo.ysq.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.roncoo.ysq.dao.HomePagecontrolMapper;
import com.roncoo.ysq.entity.HomeBottompage;
import com.roncoo.ysq.dao.HomeBottompageMapper;
import com.roncoo.ysq.entity.HomePagecontrol;
import com.roncoo.ysq.service.IHomeBottompageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yuanshuaiqiang
 * @since 2021-03-24
 */
@Service
public class HomeBottompageServiceImpl extends ServiceImpl<HomeBottompageMapper, HomeBottompage> implements IHomeBottompageService {

    @Resource
    private HomeBottompageMapper homeBottompageMapper;
    @Resource
    private HomePagecontrolMapper homePagecontrolMapper;
    @Override
    public IPage<HomeBottompage> findAll(Page page, HomeBottompage homeBottompage) {
         //条件构造器
        QueryWrapper<HomeBottompage> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(homeBottompage.getBTitle())){
            queryWrapper.like("t.b_title",homeBottompage.getBTitle()).or().like("hbb.b_title",homeBottompage.getBTitle());
        }
        if (homeBottompage.getStatusId()!=null){
            queryWrapper.eq("t.status_id",homeBottompage.getStatusId()).or().eq("hbb.status_id",homeBottompage.getStatusId());
        }
        IPage<HomeBottompage> all=homeBottompageMapper.findAll(page,queryWrapper);
        return all;
    }

    @Override
    public Boolean removeByPid(Integer yId) {
        QueryWrapper<HomeBottompage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("y_id",yId).or().eq("y_pid",yId);
        int delete = homeBottompageMapper.delete(queryWrapper);
//        System.out.println(delete+"========");
        if (delete!=0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Boolean upddataByPid(HomeBottompage homeBottompage) {
        /*QueryWrapper<HomeBottompage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("y_id",homeBottompage.getYId()).or().eq("y_pid",homeBottompage.getYId());
        int update = homeBottompageMapper.update(homeBottompage, queryWrapper);*/
        int update=homeBottompageMapper.upddateByPid(homeBottompage);

        if (update==0){
            return false;
        }else {
            return true;
        }
    }

    @Override
    public HomePagecontrol findPage(Integer yId) {
        QueryWrapper<HomePagecontrol> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("yid",yId);
        HomePagecontrol homePagecontrol = homePagecontrolMapper.selectOne(queryWrapper);
        return homePagecontrol;
    }

    /**
     * before 根据status查询数据
     * @return
     */
    @Override
    public List<HomeBottompage> findByStatus() {
        //条件构造器
        //QueryWrapper<HomeBottompage> queryWrapper = new QueryWrapper<>();
        List<HomeBottompage> all=homeBottompageMapper.findByStatus();
        return all;
    }
}
